#
# Download the base packages for Debian-Sarge and create a versabox
# package from them.  Requires the right version of debootstrap to be
# installed.
#

ALL=sarge.tar initscripts.tar vip.ini

all: Sarge.pkg

initscripts.tar: initscripts
	rm -f $@
	../../versatar -cf $@ -C initscripts .

filesystem.base:
	debootstrap --download-only \
		sarge $@ http://http.us.debian.org/debian

filesystem: filesystem.base
	rm -rf $@ $@.tmp
	cp -a filesystem.base $@.tmp
	debootstrap \
		sarge $@.tmp http://http.us.debian.org/debian
	rm -f $@.tmp/var/cache/apt/archives/*.deb \
	      $@.tmp/var/lib/apt/lists/*invalid* \
	      $@.tmp/var/cache/debconf/config.dat-old
	mv $@.tmp $@

.PRECIOUS: sarge.tar
sarge.tar: filesystem
	rm -f $@ $@.tmp
	../../versatar -cf $@.tmp filesystem
	mv $@.tmp $@

.PRECIOUS: sarge.vip
sarge.vip: ${ALL}
	rm -f $@
	zip $@ ${ALL}

# Always rebuild this: it depends on the whole versabox package, which
# might have changed.
.PHONY: Sarge.pkg
Sarge.pkg: sarge.vip
	../../versapack sarge.vip Sarge.pkg

clean:
	rm -rf Sarge.pkg filesystem filesystem.base
	rm -f sarge.vip sarge.tar *~
